#!/usr/local/bin/bash
#
## run this first to generate Makefile

test -d objs || mkdir objs

#====check os and platform======================

echo "checking OS and machine..."

#handle source file 
TODAY=`date +%Y-%m-%d`
AX_MAKEFILE=Makefile
AX_SYSTEM=`uname -s 2>/dev/null`
AX_MACHINE=`uname -m 2>/dev/null`

echo "platform:  $AX_SYSTEM  $AX_MACHINE"

AX_OS_SPECIAL=""
case $AX_SYSTEM in 
    FreeBSD)
        AX_OS_SPECIAL+="-DOS_FREEBSD "
        AX_OS_SPECIAL+="-DHAVE_KQUEUE "
        AX_MAKE=gmake
    ;;
    Linux)
        AX_OS_SPECIAL+="-DOS_LINUX "
        AX_OS_SPECIAL+="-DHAVE_EPOLL "
        AX_MAKE=make
     ;;

     *)
         echo "unknown OS"
         AX_CONF_ERR="Unknown OS"
     ;;
esac

case "$AX_MACHINE" in 
    i386 | i686)
        AX_OS_SPECIAL+="-DMACH_32BIT"
    ;;
    
    amd64 | x86_64)
        AX_OS_SPECIAL+="-DMACH_64BIT "
    ;;

    *)
        echo "unknown machine"
        AX_CONF_ERR="Unknown OS"
esac

# generate Makefile
mkdir -p objs/src/common objs/src/event objs/src/game objs/src/netd
rm -f $AX_MAKEFILE

#append to Makefile
cat << END      >> $AX_MAKEFILE
# Makefile of Axon Game Engine
# Last Generated: $TODAY

# Warning: 
#   The Makefile is auto generated by genmake, don't edit it
#   Edit Makefile.body instead  

MAKE=$AX_MAKE
OS_SPECIAL=$AX_OS_SPECIAL

END

cat Makefile.body >> $AX_MAKEFILE
echo "Makefile generated"

